package cn.base.springutil.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.cglib.beans.BeanMap;

import java.util.HashMap;
import java.util.Map;
@Slf4j
public class _BeanUtils {
	public static <T> Map<String, Object> bean2Map(T bean) {
        Map<String, Object> map = new HashMap<String,Object>();
        if (bean != null) {
            BeanMap beanMap = BeanMap.create(bean);
            for (Object key : beanMap.keySet()) {
                map.put(key.toString(), beanMap.get(key));
            }
        }
        return map;
    }
	public static <T> T createInstance(String className,Class<T> assignableTo)  {
		Class<?> clazz;
		try {
			clazz = Class.forName(className);
		} catch (ClassNotFoundException e) {
            log.error("ClassNotFoundException:{}",className);
			throw new RuntimeException(e);
		}
		return BeanUtils.instantiateClass(clazz, assignableTo);
    }
    
    
}
